home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Borland Plateform / Turbo Prolog 2 / EXAMPL58.PRO < prev    next >
Encoding:
Prolog Source  |  1986-04-01  |  1.0 KB  |  30 lines

  1.                    /* Program 58 */
  2. domains
  3.     key = cr;esc;break;tab;btab;del;bdel;ins;end;home;
  4.           fkey(integer);up;down;left;right;char(CHAR);other
  5. predicates
  6.     readkey(key)
  7.     key_code(key,char,integer)
  8.     key_code2(key,integer)
  9. goal
  10.     write("Keyboard test. Press a key!"),
  11.     readkey(Key),
  12.     write("The ",Key,"-key was pressed").
  13. clauses
  14.     readkey(Key):-
  15.         readchar(T),char_int(T,Val),key_code(Key,T,Val).
  16.  
  17.     key_code(Key,_,0):-
  18.         readchar(T),char_int(T,Val),key_code2(Key,Val),!.
  19.     key_code(break,_,3):-!.      key_code(bdel,_,8):-!.
  20.     key_code(tab,_,10):-!.       key_code(cr,_,13):-!.
  21.     key_code(esc,_,27):-!.       key_code(char(T),T,_).
  22.  
  23.     key_code2(btab,15):-!.       key_code2(home,71):-!.
  24.     key_code2(up,72):-!.         key_code2(left,75):-!.
  25.     key_code2(right,77):-!.      key_code2(end,79):-!.
  26.     key_code2(down,80):-!.       key_code2(ins,82):-!.
  27.     key_code2(del,83):-!.
  28.     key_code2(fkey(N),V):- V>58, V<70, N=V-58, !.
  29.     key_code2(other,_).
  30.